package com.jt.safe.ui.adpter

import android.graphics.Color
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jt.safe.R
import com.jt.safe.entity.DateBean

class SelectSubTimeAdapter() :
    BaseQuickAdapter<DateBean, BaseViewHolder>(R.layout.select_time_sub_item) {
    private var priceMap = mutableMapOf<String, String>()

    fun setPriceMap(priceMap: MutableMap<String, String>) {
        this.priceMap = priceMap
        notifyDataSetChanged()
    }


    override fun convert(helper: BaseViewHolder, bean: DateBean) {
        val mDay = helper.getView<TextView>(R.id.day)
        val group = helper.getView<LinearLayout>(R.id.group)
        val mSubDay = helper.getView<TextView>(R.id.subday)
        val mGovHolidayHint = helper.getView<TextView>(R.id.gov_holiday_hint)
        mDay.text = bean.getShownDay();
        if (!TextUtils.isEmpty(priceMap.get(bean.getFomartTag()))) {
            mSubDay.text = "￥${priceMap.get(bean.fomartTag)}";
        } else if (!TextUtils.isEmpty(bean.getSpecialDayTag())) {
            mSubDay.setText(bean.getSpecialDayTag());
        } else {
            mSubDay.setText(bean.getNongliDay());
        }
        // 法定节假日默认隐藏
        mGovHolidayHint.setVisibility(View.INVISIBLE);
        if (!bean.isCanSelect) {
            // 不可选
            mDay.setTextColor(Color.parseColor("#D5D5D5"));
        } else if (bean.isGovHoliday()) {
            // 节假日
            mGovHolidayHint.visibility = View.VISIBLE;
            mGovHolidayHint.text = "休";
            mGovHolidayHint.setTextColor(Color.parseColor("#D83939"));
            mDay.setTextColor(Color.parseColor("#D83939"));
        } else if (bean.isGovHolidayWork()) {
            // 调休工作日
            mGovHolidayHint.visibility = View.VISIBLE;
            mGovHolidayHint.text = "班";
            mGovHolidayHint.setTextColor(Color.parseColor("#111111"));
            mDay.setTextColor(Color.parseColor("#111111"));
        } else if (bean.dayOfWeek == 1 || bean.dayOfWeek == 7) {
            //正常周末
            mDay.setTextColor(Color.parseColor("#D83939"));
        } else {
            //其他工作日
            mDay.setTextColor(Color.parseColor("#111111"));
        }
        if (bean.isCheck) {
            //选中 blue
            group.setBackgroundResource(R.drawable.calendar_check_bg);
        } else {
            group.setBackgroundColor(Color.parseColor("#00000000"));
        }
    }

}